package com.sky.mapper;


import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;

@Mapper
public interface ReportMapper {
    /**
     * 通过日期计算营业额
     * @param beginTime
     * @param endTime
     * @return
     */
    @Select("select sum(amount) from orders where order_time between #{beginTime} and #{endTime}")
    Double getSum(LocalDateTime beginTime, LocalDateTime endTime);

    /**
     * 统计所有用户数量
     * @return
     */

    @Select("select count(*) from employee")
    Integer getTotalUser();

    /**
     * 查询每日的新增用户数量
     * @param beginTime
     * @param endTime
     * @return
     */
    @Select( "select count(*) from employee where create_time between #{beginTime} and #{endTime}")
    Integer getNewUser(LocalDateTime beginTime, LocalDateTime endTime);

    /**
     *  统计所有的订单数量
     * @return
     */
     @Select("select count(*) from orders")
    Integer getTotalOrderCount();


    /**
     * 统计有效的订单数量 通过status=5  5/已完成来判断
     * @return
     */
     @Select("select count(*) from orders where status = 5")
    Integer getValidTotalOrderCount();

    /**
     * 统计每天的订单总数
     * @param beginTime
     * @param endTime
     * @return
     */
    @Select("select count(*) from orders where order_time between #{beginTime} and #{endTime}")
    Integer getOrderCount(LocalDateTime beginTime, LocalDateTime endTime);

    /**
     * 统计每天的有效的订单总数
     * @param beginTime
     * @param endTime
     * @return
     */
    @Select("select count(*) from orders where status = 5 and order_time between #{beginTime} and #{endTime}")
    Integer getValidOrderCount(LocalDateTime beginTime, LocalDateTime endTime);
}
